#include "variable.h"

namespace fcsp {
using namespace std;

Variable::Variable() {
  ++seed_;
  id_ = seed_;
}

Variable::Variable(map<int, double> preferences): preferences_(preferences) {
  ++seed_;
  id_ = seed_;
}

int Variable::seed_ = -1;

void Variable::AddAdjacent(Variable &adjacent) {
  adjacents_.insert(&adjacent);
}

void Variable::RemoveAdjacent(Variable &adjacent) {
  adjacents_.erase(&adjacent);
}

void Variable::RemoveValue(int value) {
  preferences_.erase(value);
}

bool Variable::IsValue(int value) {
  return preferences_.count(value) > 0;
}

double Variable::GetPreference(int value) {
  double preference = 0.0;
  if (IsValue(value))
    preference = preferences_[value];
  return preference;
}

void Variable::SetPreference(int value, double preference) {
  preferences_[value] = preference;
}
} // namespace fcsp
